#include "QSketchLineAction.h"

#include <iostream>
#include "../QSketchManager.h"
#include "Core/MainWindow.h"
#include "Sketch/QSketchManager.h"
#include "Core/TempActorManager.h"

QSketchLineAction::QSketchLineAction(QSketchManager* parent, MainWindow* mainWindow)
	: QSketchCurveAction(parent, mainWindow)
{}

QSketchLineAction::~QSketchLineAction()
{}

void QSketchLineAction::StartCreate()
{
	std::cout << "line create" << std::endl;
}

void QSketchLineAction::OnMouseMove(const gp_Pnt& point)
{
}

void QSketchLineAction::OnLeftDown(const gp_Pnt& point)
{
	if (!bIsConfirmStart)
	{
		bIsConfirmStart = true;
		m_startPoint = point;

		m_startPointActorID = m_mainWindow->GetTempActorManager()->GetUnallocatedActor(0.01);
		m_mainWindow->GetTempActorManager()->SetActorVisible(m_startPointActorID, true, point);
	}
	else
	{
		m_endPoint = point;
		// 确认创建
		Handle(QIVtkSelectionPipeline) actor = m_mainWindow->createLine(m_startPoint, m_endPoint);
		actor->m_featureShape.reset(new FeatureShapeLine(actor->OccShape(), m_startPoint, m_endPoint));
		m_sketchManager->m_points[EVertexType::EdgeEndVertex].push_back(m_startPoint);
		m_sketchManager->m_points[EVertexType::EdgeEndVertex].push_back(m_endPoint);
		m_sketchManager->m_points[EVertexType::EdgeDividedVertex].push_back((m_startPoint + m_endPoint) * 0.5);
		m_sketchManager->EndCreateSketchCurve(actor);
	}
}

void QSketchLineAction::Reset()
{
	m_mainWindow->GetTempActorManager()->FreeActor(m_startPointActorID);

	bIsConfirmStart = false;
	m_startPoint = gp_Pnt();
	m_endPoint = gp_Pnt();
	m_startPointActorID = 255;
}
